<?php

namespace App\Observers;

use App\Models\Borker;
use App\server\RedisServer;
use Illuminate\Support\Facades\Mail;

class BrokerObserver
{
    /**
     * Handle the Broker "created" event.
     *
     * @param \App\Models\Borker $broker
     * @return void
     */
    public function created(Borker $broker)
    {
        $redis = RedisServer::createRedisObject();
        $redis->select(3);
        $borkerdata = $broker->toArray();
        $redis->hSetone($borkerdata);
    }

    /**
     * Handle the Broker "updated" event.
     *
     * @param \App\Models\Borker $broker
     * @return void
     */
    public function updated(Borker $broker)
    {
        $data = $broker->toArray();
        $redis = RedisServer::createRedisObject();
        $redis->select(3);
        foreach ($data as $k => $v) {
            $redis->hset($data['id'], $k, $v);
        }
    }

    /**
     * Handle the Broker "deleted" event.
     *
     * @param \App\Models\Borker $broker
     * @return void
     */
    public function deleted(Borker $broker)
    {
        //
    }

    /**
     * Handle the Broker "restored" event.
     *
     * @param \App\Models\Borker $broker
     * @return void
     */
    public function restored(Borker $broker)
    {
        //
    }

    /**
     * Handle the Broker "force deleted" event.
     *
     * @param \App\Models\Borker $broker
     * @return void
     */
    public function forceDeleted(Borker $broker)
    {
        //
    }
}
